//
//  BookTopicsDetailFirstCell.m
//  FreeTrip
//
//  Created by 352324497@qq.com on 15/11/27.
//  Copyright © 2015年 邓芮. All rights reserved.
//

#import "BookTopicsDetailFirstCell.h"

@implementation BookTopicsDetailFirstCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        self.selectionStyle = NO;
        
        CGFloat height = KScreenWidth / 1600 * 1060;
        self.backgroundImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth, height)];
        [self.contentView addSubview:_backgroundImageView];
        
        UIView *coverView = [[UIView alloc]initWithFrame:self.backgroundImageView.frame];
        coverView.backgroundColor = [UIColor blackColor];
        coverView.alpha = 0.2;
        [self.contentView addSubview:coverView];
        
        CGFloat x = 10 * KScreenWidth / 375;
        self.nameLabel = [[UILabel alloc]initWithFrame:CGRectMake(x + x, height / 6 * 4, (KScreenWidth - 10 * 2), height / 6)];
        self.nameLabel.textColor = [UIColor whiteColor];
        self.nameLabel.font = [UIFont boldSystemFontOfSize:26 * KScreenWidth / 375];
        [self.contentView addSubview:_nameLabel];
        
        self.titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(x, height / 6 * 5, (KScreenWidth - 10 * 2), height / 6)];
        self.titleLabel.textColor = [UIColor whiteColor];
        self.titleLabel.font = [UIFont boldSystemFontOfSize:20 * KScreenWidth / 375];
        [self.contentView addSubview:_titleLabel];
        
        self.myDescriptionLabel = [[UILabel alloc]initWithFrame:CGRectMake(10 * KScreenWidth / 375, 10 * KScreenWidth / 375 + height, KScreenWidth - 20 * KScreenWidth / 375, 20 * KScreenWidth / 375)];
        self.myDescriptionLabel.numberOfLines = 0;
        self.myDescriptionLabel.font = [UIFont systemFontOfSize:16 * KScreenWidth / 375];
        [self.contentView addSubview:_myDescriptionLabel];
    }
    return self;
}

-(void)setModel:(BookTopicsDetailModel *)model
{
    
    CGFloat height = KScreenWidth / 1600 * 1060;
    _model = model;
    if (model.myDescription.length != 0)
    {
        [self.backgroundImageView sd_setImageWithURL:[NSURL URLWithString:model.wImageurl] placeholderImage:[UIImage imageNamed:@"placeholder"]];
        self.nameLabel.text = model.wName;
        self.titleLabel.text = model.wTitle;
        self.myDescriptionLabel.text = model.myDescription;
        
        CGRect bounds = [model.myDescription boundingRectWithSize:CGSizeMake(KScreenWidth - 20 * KScreenWidth / 375, 10000 * KScreenWidth / 375) options:(NSStringDrawingUsesLineFragmentOrigin) attributes:[NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:16 * KScreenWidth / 375] forKey:NSFontAttributeName] context:nil];
        self.myDescriptionLabel.frame = CGRectMake(10 * KScreenWidth / 375, 10 * KScreenWidth / 375 + height, KScreenWidth - 20 * KScreenWidth / 375, bounds.size.height + 5);
    }
    
}

+(CGFloat)heightForCell:(BookTopicsDetailModel *)model
{
    CGFloat height = (KScreenWidth - 10 * 2 ) / 1600 * 1060;
    if (model.myDescription.length != 0)
    {
        CGRect bounds = [model.myDescription boundingRectWithSize:CGSizeMake(KScreenWidth - 20 * KScreenWidth / 375, 10000 * KScreenWidth / 375) options:(NSStringDrawingUsesLineFragmentOrigin) attributes:[NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:16 * KScreenWidth / 375] forKey:NSFontAttributeName] context:nil];
        
        return height + bounds.size.height + 40 * KScreenWidth / 375;
    }
    return 0;
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
